﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Transactions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using OnlineTestBLL;
using OnlineTestModel;

namespace OnlineTestUI.BackManager
{
    //完成
    public partial class addchoice : System.Web.UI.Page
    {
        protected QuestionsBLL qb = new QuestionsBLL();
        protected QuestionItemsBLL qib = new QuestionItemsBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
       

        protected void BtAdd_Click(object sender, EventArgs e)
        {
            
            Questions q = new Questions();
            q.QuestionName = tbquestion.Text;
            q.VersionNumber = 1;
            q.PreDifficult = tbpredifficult.Text;
            q.TrueDifficult = tbpredifficult.Text;//首次加入新题时，真实难度和预测难度相同
            q.Chapter = tbchapter.Text;
            q.Part = tbpart.Text;
            q.QuestionTypeId = 1;
            q.BlankLine = Convert.ToInt32(tbblankline.Text);
            q.CorrectAnswer = taanswer.Text;
            q.TotalCount = 0;
            q.CorrectCount = 0;
            q.PartitionDegree = tbpartitiondegree.Text;
            q.ParentId = 0;
            q.Status = 1;
            string[] s = Request["hidProperty"].Split(new char[] {'&'},System.StringSplitOptions.RemoveEmptyEntries);
            //每次对试题的修改都是创建新题

            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    int result = qb.Add(q);
                    if (result > 0)
                    {
                        List<QuestionItems> questionItemList = new List<QuestionItems>();
                        for (int i = 0; i < s.Length; i++)
                        {
                            string[] ss = s[i].Split(new char[] {'|'});
                            QuestionItems qi = new QuestionItems();
                            qi.ItemGrade = Convert.ToInt32(ss[1]);
                            qi.ItemName = ss[0];
                            qi.QuestionId = result;
                            qib.Add(qi);
                        }
                        ts.Complete();
                       

                        Alert.Show("添加填空题成功");
                        

                    }
                    else
                    {
                        Alert.Show("出现错误");
                    }

                }

            }
            catch(Exception)
            {
                Alert.Show("出现错误");
            }
         
        }
    }
}